package com.ksy.common.login;



import com.ksy.common.utils.LogTool;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Ksy
 */

public class LoginListenerManager {
    private static LoginListenerManager manager;
    private List<LoginNoticeInterface> listenrs;

    public static LoginListenerManager getInstance() {
        if (manager == null) {
            synchronized (LoginListenerManager.class) {
                if (manager == null) {
                    manager = new LoginListenerManager();
                    return manager;
                }
            }
        }
        return manager;
    }

    public void registerListener(LoginNoticeInterface loginNoticeInterface) {
        if (loginNoticeInterface == null) {
            return;
        }
        if (listenrs == null) {
            listenrs = new ArrayList<>();
        }
        listenrs.add(loginNoticeInterface);
    }

    public void unRegisterListener(LoginNoticeInterface loginNoticeInterface) {
        if (loginNoticeInterface == null) {
            return;
        }
        if (listenrs == null) {
            listenrs = new ArrayList<>();
        }
        listenrs.remove(loginNoticeInterface);
    }

    public final static String ACTION_WeChat_Login = "ACTION_WeChat_Login";


    public void notifyListener(LoginAction loginAction) {
        if (listenrs == null) {
            return;
        }
        LogTool.e("listenrs     " + listenrs.size());
        for (LoginNoticeInterface listenr : listenrs) {
            listenr.loginNotify(loginAction);
        }
    }
}
